package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import static com.sky.constant.OthersConstant.SHOP_STATUS;

@RestController("adminShopController")
@Slf4j
@Api(tags = "设置营业状态接口")
@RequestMapping("/admin/shop")
public class ShopController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @PutMapping("/{status}")
    @ApiOperation(value = "设置营业状态")
    public Result setShopStatus(@PathVariable Integer status){

        //设置redis中店铺营业状态
        stringRedisTemplate.opsForValue().set(SHOP_STATUS,status.toString());
        return Result.success();
    }

    @GetMapping("/status")
    @ApiOperation(value = "查询营业状态")
    public Result<Integer> queryStatus(){
        return Result.success(Integer.parseInt(stringRedisTemplate.opsForValue().get(SHOP_STATUS)));
    }
}
